package com.sky.controller.admin;

import com.sky.constant.StatusConstant;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;

import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;

import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api("菜品管理")
@RestController("adminDishController")
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dto) {
        return dishService.page(dto);

    }

    @ApiOperation("根据id查询菜品")
    @GetMapping("/{id}")
    public Result getDish(@PathVariable Long id) {
        return dishService.getById(id);

    }

    @ApiOperation("修改菜品信息")
    @PutMapping
    @CacheEvict(cacheNames = "dishCache", allEntries = true)
    public Result update(@RequestBody DishDTO dto) {
        return dishService.upadteDish(dto);
    }

    @ApiOperation("新增菜品")
    @PostMapping
    @CacheEvict(cacheNames = "dishCache", allEntries = true)
    public Result addDish(@RequestBody DishDTO dto) {
        return dishService.addDish(dto);
    }

    @ApiOperation("启售停售")
    @PostMapping("status/{status}")
    @CacheEvict(cacheNames = "dishCache",allEntries = true)
    public Result statusDish(@PathVariable Integer status, Long id) {
        return dishService.statusDish(status, id);

    }

    @ApiOperation("批量删除")
    @DeleteMapping
    @CacheEvict(cacheNames = "dishCache",allEntries = true)
    public Result delete(@RequestParam List<Long> ids) {
        return dishService.delete(ids);

    }

    @ApiOperation("分类id查询菜品")
    @GetMapping("/list")
    public Result getBycategoryId(DishDTO dto) {
        return dishService.getBycategoryId(dto);

    }


}
